<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="pragma" content="no-cache" />
	<link rel="stylesheet" href="/css/style.css" type="text/css"/>
	<script type="text/javascript" src="/js/jquery.js"></script>
	<script type="text/javascript" src="/js/util.js"></script>
</head>
<script type="text/javascript">
//////////////////////////////////////////////////////////////////////
////  email = "wenpin.qian@happyelements.com"                     ////
////  team = "Athene"                                             ////
////  warnings = "This is generated page,Do Not Modify!";         ////
////  tips = "Opera & IE not supported|Chrome & Safari sugguested"////
//////////////////////////////////////////////////////////////////////
window.returnValue=0;

$(document).ready(function() {
listselectors();
});

function addmap() {
	var addmapUrl = "/map/add/";
	var nameValue = $("#name").val();
	if(!checkString("名字",nameValue,false)) {
		return;
	}
	var nameParam = "name=" + xparseString(nameValue);
		
	var campaignIdsValue = $("#campaignIds").val();
	
	var campaignIdsParam = "campaignIds=" + campaignIdsValue;
		
	var mapresValue = $("#mapres").val();
	
	var mapresParam = "mapres=" + mapresValue;
			
	$.ajax({
		   type: "POST",
		   url: addmapUrl,
		   data:   nameParam +'&'+ campaignIdsParam +'&'+ mapresParam ,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
			       window.returnValue=1;
			       beforeWindowClose();
				   window.close();
			   }else {
				  errDialog(data.message);
			   }
		   }
	});
}

function listselectors() {
}

function addcampaignIds() {
	var campaignIdsstr = $("#campaignIds").val();
	var returnCallback = function(retvalue) {
		$('#campaignIds').val(retvalue);
	}
	openDialog("/pages/core/SelectorArray.html",["Campaign","Campaign",campaignIdsstr],"dialogWidth:600px;dialogHeight:600px;status:no;help:no;center:yes",returnCallback);
}

function openResource(fieldname,dependfield) {
	var param = "";
	if(dependfield!="") {
		param = $("#" + dependfield).val()
		if(param == null || param == "") {
			alert("你先把【" + $("#lbl_" + dependfield).html() + "】填了再上传");
			return;
		}
	}
	resourceDialog("map",$("#" + fieldname).val(),param,function(result) {
		if(result != undefined && result != "") {
			$("#" + fieldname).val(result);
		}
	});
}

function beforeWindowClose() {
	if(window.returnCallback) {
		window.returnCallback(window.returnValue);
	}
	window.onbeforeunload = null;
	return true;
}

</script>
<body onunload="beforeWindowClose()">
	<div class="addarea">
	<form action="/map/add" method="post">
		<table>
			<tbody>				
					<tr>					<td>
						<label for="name" id="lbl_name">名字</label>
													<input type="text" id="name" name="name" /><span class="tips">[文字]</span>
											</td>
									
										<td>
						<label for="campaignIds" id="lbl_campaignIds">战役点</label>
													<input type="text" id="campaignIds" name="campaignIds" value="[]" disabled/>
							<input type="button" value="..." onclick="addcampaignIds()"/>
											</td>
					</tr>				
					<tr>					<td>
						<label for="mapres" id="lbl_mapres">地图资源</label>
													<input type="text" id="mapres" name="mapres" disabled/>
							<input type="button" value="..." onclick="openResource('mapres','')"/><span class="tips">[资源]</span>
											</td>
												</tbody>
		</table>
		<input type="button" onclick="addmap()" value="添加"/>
	</form>
	</div>
</body>